/*
 * Copyright 2005-2013 biz-united. All rights reserved.
 * Support: http://www.biz-united.com.cn
 * License: http://www.biz-united.com.cn/?page_id=5&act=3
 */
package net.biz.dao;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import net.biz.Filter;
import net.biz.Page;
import net.biz.Pageable;
import net.biz.entity.Member;
import net.biz.entity.Order;
import net.biz.entity.Order.OrderStatus;
import net.biz.entity.Order.PaymentStatus;
import net.biz.entity.Order.ShippingStatus;

import com.home766.dto.OrderBrandCountDTO;
import com.home766.entity.Shops;

/**
 * Dao - 订单
 * 
 * @author BIZ Team
 * @version 3.0
 */
public interface OrderDao extends BaseDao<Order, Long> {

	/**
	 * 根据订单编号查找订单
	 * 
	 * @param sn
	 *            订单编号(忽略大小写)
	 * @return 订单，若不存在则返回null
	 */
	Order findBySn(String sn);

	/**
	 * 查找订单
	 * 
	 * @param member
	 *            会员
	 * @param count
	 *            数量
	 * @param filters
	 *            筛选
	 * @param orders
	 *            排序
	 * @return 订单
	 */
	List<Order> findList(Member member, Integer count, List<Filter> filters, List<net.biz.Order> orders);

	/**
	 * 查找订单分页
	 * 
	 * @param member
	 *            会员
	 * @param pageable
	 *            分页信息
	 * @return 订单分页
	 */
	Page<Order> findPage(Member member, Pageable pageable);

	/**
	 * 查找订单分页
	 * 
	 * @param orderStatus
	 *            订单状态
	 * @param paymentStatus
	 *            支付状态
	 * @param shippingStatus
	 *            配送状态
	 * @param hasExpired
	 *            是否已过期
	 * @param pageable
	 *            分页信息
	 * @return 商品分页
	 */
	Page<Order> findPage(Shops shops, Long adminId, Date beginDate,
                         Date endDate, Integer schemeStatus, Integer schemePaymentStatus,
                         Integer orderType, OrderStatus orderStatus,
                         PaymentStatus paymentStatus, ShippingStatus shippingStatus,
                         Boolean hasExpired, Pageable pageable, String shopName, Date createDate, Long provinceId, Long cityId, Long areaId, boolean flag);

	/**
	 * 查询订单数量
	 * 
	 * @param orderStatus
	 *            订单状态
	 * @param paymentStatus
	 *            支付状态
	 * @param shippingStatus
	 *            配送状态
	 * @param hasExpired
	 *            是否已过期
	 * @return 订单数量
	 */
	Long count(OrderStatus orderStatus, PaymentStatus paymentStatus, ShippingStatus shippingStatus, Boolean hasExpired);

	/**
	 * 查询等待支付订单数量
	 * 
	 * @param member
	 *            会员
	 * @return 等待支付订单数量
	 */
	Long waitingPaymentCount(Member member);

	/**
	 * 查询等待发货订单数量
	 * 
	 * @param member
	 *            会员
	 * @return 等待发货订单数量
	 */
	Long waitingShippingCount(Member member);

	/**
	 * 获取销售额
	 * 
	 * @param beginDate
	 *            起始日期
	 * @param endDate
	 *            结束日期
	 * @return 销售额
	 */
	BigDecimal getSalesAmount(Date beginDate, Date endDate);

	/**
	 * 获取销售量
	 * 
	 * @param beginDate
	 *            起始日期
	 * @param endDate
	 *            结束日期
	 * @return 销售量
	 */
	Integer getSalesVolume(Date beginDate, Date endDate);

	/**
	 * 释放过期订单库存
	 */
	void releaseStock();
	/***
	 * 单品订单报表
	 * @param schemeStatus
	 * @param orderType
	 * @param orderStatus
	 * @param paymentStatus
	 * @param shippingStatus
	 * @param hasExpired
	 * @param pageable
	 * @return
	 */
	List<Order> getOrderList(Shops shops, Long adminId, Date beginDate, Date endDate, Integer schemeStatus, Integer orderType, OrderStatus orderStatus, PaymentStatus paymentStatus, ShippingStatus shippingStatus, Boolean hasExpired, Pageable pageable);
	
	int updateServiceShop(Long id, Shops shops);
	
	/***
	 * 订单报表集合数据查询
	 * @param pageable
	 * @param shopName
	 * @param createDate
	 * @param provinceId
	 * @param cityId
	 * @param areaId
	 * @return
	 */
	List<Order> findExportList(String shopName, Date beginDate, Date endDate, Date createDate, Long provinceId, Long cityId, Long areaId);
	
	/**
	 * 统计订单中各品牌的数量
	 * @return
	 */
	List<OrderBrandCountDTO> countOrderBrandNumber();

}